package 高频题;

import java.util.Arrays;

public class 超级次方_372 {
    int base = 1337;

    public static void main(String[] args) {
        System.out.println(new 超级次方_372().superPow(2, new int[]{1,0}));
    }


    public int superPow(int a, int[] b) {
        //base case：任何数的0次方都是1
        if (b == null || b.length == 0) {
            return 1;
        }
        //取出最后一个数
        int last = b[b.length - 1];
        //更新一下b
        b = Arrays.copyOfRange(b, 0, b.length - 1);

        int part1 = myPow(a, last);
        int part2 = myPow(superPow(a, b), 10);
        return (part1 * part2) % base;
    }

    //计算a的k次方，然后与base求模
    public int myPow(int a, int k) {
        //对因子取模 基于(a*b)%k = (a%k)(b%k)%k
        a = a%base;
        int res = 1;
        for (int i = 0; i < k; i++) {
            res = res*a;
            res = res%base;
        }
        return res;

    }
}
